package com.woniu40.petai_user.mapper;

import com.woniu40.petai_user.entity.Comment;
import com.woniu40.petai_user.vo.CommentVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface CommentMapper {
    int deleteByPrimaryKey(Integer commentId);

    int insert(Comment record);

    Comment selectByPrimaryKey(Integer commentId);

    List<Comment> selectAll();

    int updateByPrimaryKey(Comment record);
    @Select("SELECT * FROM t_comment WHERE user_id = #{value} ORDER BY create_time DESC")
    List<Comment> selectByUserid(Integer userid);

    @Insert("INSERT INTO t_comment VALUES(NULL , #{userId} , #{dynamicId} , #{commentContent} , #{createTime} , #{parentId} , #{parentUserId} , #{commentStatus})")
    int insert0(CommentVo commentVo);

    // 查询父级评论
    @Select("SELECT c.*,u.user_name FROM t_comment c , t_user u WHERE u.user_id = c.user_id AND c.parent_id = -1 AND c.dynamic_id = #{dynamicId} ORDER BY create_time DESC")
    List<CommentVo> findParentIdNull(@Param("dynamicId") Integer dynamicId);
    // 查询以及评论
    @Select("SELECT c.*,u.user_name FROM t_comment c , t_user u WHERE u.user_id = c.user_id AND  c.comment_id = #{commentId} ORDER BY create_time DESC")
    List<CommentVo> findParentIdNotNull(@Param("commentId") Integer commentId);
    // 查询二级评论及其子评论
    @Select("SELECT c.*,u.user_name FROM t_comment c , t_user u WHERE u.user_id = c.user_id AND  c.parent_id = #{childId} ORDER BY create_time DESC")
    List<CommentVo> findByReplayId(@Param("childId") Integer childId);
}